package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.StObject;
import com.ruoyi.system.service.IStObjectService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 对象管理Controller
 * 
 * @author wmao
 * @date 2024-07-19
 */
@Controller
@RequestMapping("/system/stobj")
public class StObjectController extends BaseController
{
    private String prefix = "system/stobj";

    @Autowired
    private IStObjectService stObjectService;

    @RequiresPermissions("system:stobj:view")
    @GetMapping()
    public String stobj()
    {
        return prefix + "/stobj";
    }

    /**
     * 查询对象管理列表
     */
    @RequiresPermissions("system:stobj:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StObject stObject)
    {
        startPage();
        List<StObject> list = stObjectService.selectStObjectList(stObject);
        return getDataTable(list);
    }

    /**
     * 导出对象管理列表
     */
    @RequiresPermissions("system:stobj:export")
    @Log(title = "对象管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StObject stObject)
    {
        List<StObject> list = stObjectService.selectStObjectList(stObject);
        ExcelUtil<StObject> util = new ExcelUtil<StObject>(StObject.class);
        return util.exportExcel(list, "对象管理数据");
    }

    /**
     * 新增对象管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存对象管理
     */
    @RequiresPermissions("system:stobj:add")
    @Log(title = "对象管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StObject stObject)
    {
        return toAjax(stObjectService.insertStObject(stObject));
    }

    /**
     * 修改对象管理
     */
    @RequiresPermissions("system:stobj:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        StObject stObject = stObjectService.selectStObjectById(id);
        mmap.put("stObject", stObject);
        return prefix + "/edit";
    }

    /**
     * 修改保存对象管理
     */
    @RequiresPermissions("system:stobj:edit")
    @Log(title = "对象管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(StObject stObject)
    {
        return toAjax(stObjectService.updateStObject(stObject));
    }

    /**
     * 删除对象管理
     */
    @RequiresPermissions("system:stobj:remove")
    @Log(title = "对象管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(stObjectService.deleteStObjectByIds(ids));
    }
}
